//*******************************************************************
//glfont2.h -- Header for glfont2.cpp
//Copyright (c) 1998-2002 Brad Fish
//See glfont.html for terms of use
//May 14, 2002
//*******************************************************************

#ifndef GLFONT2_H
#define GLFONT2_H

#include <assert.h>
#include <map>

//*******************************************************************
//GLFont Interface
//*******************************************************************

//glFont namespace
namespace glfont
{
	class GLFont;	
}

enum EFontTextEncoding
{
	NONE,
	UTF8,
	UTF16
};

enum EUnicodeByteOrder
{
	LITTLE_ENDIAN,
	BIG_ENDIAN,
};

//glFont class
class glfont::GLFont
{
public:
	//glFont character structure
	typedef struct
	{
		short ox, oy;
		float tx1, ty1;
		short tdx, tdy;
		short adv;
	} GLFontChar;
private:
	//glFont header structure
	struct 
	{
		unsigned int numchars;
		unsigned char encoding;
		short font_height;
		unsigned int tex_width, tex_height;
		std::map<int, GLFontChar> chars;
	} header;
	unsigned int tex;
	GLFontChar defChar;
public:

	//Constructor
	GLFont ();

	//Destructor
	~GLFont ();

public:
	bool Create(unsigned int tex, unsigned int tex_width, unsigned int tex_height, short font_height, unsigned char encodeing);
	void AddChar(int id, const GLFontChar& glChar);
	
	//Destroys the glFont
	void Destroy (void);

	int DecodeUTF8(const char* encodedBuffer, unsigned int* outCharLength);

	int DecodeUTF16(const char* encodedBuffer, unsigned int* outCharLength, unsigned char byteOrder = 0);

	/****** new *****/
	GLFontChar* GetChar(int id);

	float GetTextWidth(const char* text, int count);
	float GetHeight();

	int GetTextLength(const char* text);
	int GetTextChar(const char* text, int pos, int* nextPos = 0);
	int FindTextChar(const char* text, int start, int length, int ch);

	/****** new end *****/

	//Begins text output with this font
	void Begin (void);	
	
	//Template function to output a scaled, colored std::basic_string
	void DrawString(
		const char* text, float scalar, float x,
		float y, const float* top_color, const float* bottom_color, float alpha, float lastAlpha);
};

//*******************************************************************

#endif

//End of file


